﻿using Base_libs;
using Newtonsoft.Json;
using Spire.Xls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Serialization;

namespace WpfApp3
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


            Workbook wb = new Workbook();
            wb.LoadFromFile(@"C:\Users\Administrator\source\repos\WpfApp3\bin\Debug\1.xls");

            Worksheet sheet = wb.Worksheets[0];
            PropertyInfo[] infos = typeof(Test).GetProperties(BindingFlags.Instance | BindingFlags.Public);

            Dictionary<string, Pair<string, Image>> dic_data = new Dictionary<string, Pair<string, Image>>();

            foreach (var info in infos)
            {
                var bbname = info.GetCustomAttribute<BBNameAttribute>();
                if (bbname == null) continue;

                dic_data[bbname.Name] = new Pair<string, Image>();
                var val = info.GetValue(Test.Ins);

                if (val is string)
                    dic_data[bbname.Name].One = (string)val;

                sheet[bbname.Name].Value = dic_data[bbname.Name].One;

            }
            wb.SaveToFile(@"C:\Users\Administrator\source\repos\WpfApp3\bin\Debug\1.xls", FileFormat.Version2007, true);
        }



    }
    public class Test
    {
        public static readonly Test Ins = new Test();


        [BBName("m_Temperature")]
        public string temp { get { return "38.6"; } }

        [BBName("m_Hight")]
        public string Hight { get { return "11.2"; } }
    }

}
